package com.googlecode.puddle;

import com.googlecode.puddle.data.PuddleDbAdapter;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.TextView;

public class ViewShow extends Activity {

	private long show = -1;
	private PuddleDbAdapter podcastDb;
	
	private TextView showTitle;
	private TextView showDescription;
	private TextView showUrl;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.view_show);
		
		podcastDb = new PuddleDbAdapter(this);
		podcastDb.open();
		
		Intent intent = getIntent();
		show = intent.getLongExtra("show", -1);
	
		showTitle = (TextView) findViewById(R.id.ViewShowTitle);
		showDescription = (TextView) findViewById(R.id.ViewShowDescription);
		showUrl = (TextView) findViewById(R.id.ViewShowUrl);
		
		fillData();
	}

	private void fillData() {
		Cursor showCursor = podcastDb.fetchShow(show);
		
		if (showCursor == null) {
			setResult(RESULT_CANCELED);
			finish();
		}
		
		startManagingCursor(showCursor);

		String title = showCursor.getString(showCursor.getColumnIndex(PuddleDbAdapter.SHOW_TITLE));
		showTitle.setText(title);
		
		String description = showCursor.getString(showCursor.getColumnIndex(PuddleDbAdapter.SHOW_DESCRIPTION));
		showDescription.setText(description);
		
		String url = showCursor.getString(showCursor.getColumnIndex(PuddleDbAdapter.SHOW_URL));
		showUrl.setText(url);
	}

}